<?php
/**
 * Created by PhpStorm.
 * User: 李晓辉
 * Date: 2019/6/19
 * Time: 16:08
 */

namespace app\index\controller;


use app\index\model\Apply;
use app\index\model\User;
use think\Request;
use think\Session;

class Center extends Base
{
    /*
     *
     * */


    /*
     * 会员中心查询页面
     * */
    public function centerLogin()
    {
        return view("centerlogin");
    }

    /*
     * 会员中心查询页面
     * */
    public function DoCenterLogin(Request $request)
    {
        $data = $request->post();
        $user = User::where(array("idcard" => $data['idcard']))->find();
        if (!empty($user)) {
            if ($user['name'] == $data['username']) {
                Session::set("center_info", $user);
                $this->success("登陆成功", "center/CenterIndex");
            } else {
                $this->error("姓名和身份证号不匹配！");
            }
        } else {
            $this->error("该用户不存在！");
        }
    }

    /*
     * 会员中心查询页面
     * */
    public function CenterIndex(Request $request)
    {
        $user = $this->user_center_info();


        $data = array(
            "setting" => $this->getAllSetting(),
            'user' => $user,
        );
        return view("centerindex", $data);
    }

    /*
     * 会员详细信息
     * */
    public function center_info()
    {
        $user = $this->user_center_info();
        $data = array(
            "setting" => $this->getAllSetting(),
            "user" => $user,
        );
        return view("centerinfo", $data);
    }

    /*
     * 会员再修课程
     * */
    public function Course()
    {
        $user = $this->user_center_info();
        // 查询用户再修课程
        $result = Apply::alias('a')->field('a.course,c.type_name,b.classid,b.teacher,b.status,b.start_time,b.end_time,a.certificate_photo')
            ->join('myclass b','a.classid=b.classid','LEFT')
            ->join('classtype c','b.type=c.id','LEFT')
            ->where('a.idcard="' . $user['idcard'] . '"  and a.status=2 and a.classid>0')->order("a.id desc")->paginate(15,true);
        $data = array(
            "setting" => $this->getAllSetting(),
            "list" => $result,
        );
        return view("course", $data);
    }

    /*
     * 会员报名课程
     * */
    public function bmCourse()
    {
        $user = $this->user_center_info();
        // 查询用户再修课程
        $data = Apply::field('course,natrue,status,create_time,reason,comment')
            ->where('idcard=' . $user['idcard'])->select();
        $data = array(
            "setting" => $this->getAllSetting(),
            "list" => $data,
        );
        return view("bmcourse", $data);
    }

    /*
     * 会员中心退出
     * */
    public function center_exits()
    {
        Session::delete("center_info");
        $this->redirect("center/centerLogin");
    }
}